package com.longcai.piaojia.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.GoodsInfoGet;
import com.longcai.piaojia.conn.ShowTypeListGet;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/9/27.
 */
public class GoodsInfoLikeAdapter extends RecyclerView.Adapter<GoodsInfoLikeAdapter.RushedHolder> {

    private Context context;
    private List<GoodsInfoGet.GoodsInfoLikeEntity> list = new ArrayList<>();

    public OnItemClickListener onItemClickListener;

    public GoodsInfoLikeAdapter(Context context, List<GoodsInfoGet.GoodsInfoLikeEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RushedHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View convertView = LayoutInflater.from(context).inflate(R.layout.item_home_recommend_list, null);

        return new RushedHolder(convertView);
    }

    @Override
    public void onBindViewHolder(RushedHolder holder, final int position) {

//        private ImageView item_home_recommend_list_iv;
//        private TextView item_home_recommend_list_title_tv, item_home_recommend_list_time_tv;
//        private RelativeLayout item_home_recommend_list_ll;

        holder.item_home_recommend_list_ll.setPadding(ScaleScreenHelperFactory.getInstance().getWidthHeight(10),0,ScaleScreenHelperFactory.getInstance().getWidthHeight(10),0);

//        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.item_home_recommend_list_iv.getLayoutParams();
//        layoutParams.leftMargin = ScaleScreenHelperFactory.getInstance().getWidthHeight(10);
//        layoutParams.rightMargin = ScaleScreenHelperFactory.getInstance().getWidthHeight(10);
//        holder.item_home_recommend_list_iv.setLayoutParams(layoutParams);

        holder.item_home_recommend_list_title_tv.setText(list.get(position).title);
        holder.item_home_recommend_list_time_tv.setText(list.get(position).start_time);

        if (list.get(position).status.equals("0")) {

            holder.item_home_recommend_cao_iv.setVisibility(View.VISIBLE);

        } else {

            holder.item_home_recommend_cao_iv.setVisibility(View.GONE);

        }

        GlideLoader.getInstance().get(context, list.get(position).picurl, holder.item_home_recommend_list_iv, R.mipmap.home_recommend_img);

        holder.item_home_recommend_list_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onItemClickListener.onItemClick(position);

            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public interface OnItemClickListener{
        void onItemClick(int pos);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }

    class RushedHolder extends RecyclerView.ViewHolder{
        private ImageView item_home_recommend_list_iv;
        private ImageView item_home_recommend_cao_iv;
        private TextView item_home_recommend_list_title_tv, item_home_recommend_list_time_tv;
        private RelativeLayout item_home_recommend_list_ll;

        public RushedHolder(View itemView) {
            super(itemView);
            ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) itemView);

            item_home_recommend_list_ll = (RelativeLayout) itemView.findViewById(R.id.item_home_recommend_list_ll);
            item_home_recommend_list_iv = (ImageView) itemView.findViewById(R.id.item_home_recommend_list_iv);
            item_home_recommend_cao_iv = (ImageView) itemView.findViewById(R.id.item_home_recommend_cao_iv);
            item_home_recommend_list_title_tv = (TextView) itemView.findViewById(R.id.item_home_recommend_list_title_tv);
            item_home_recommend_list_time_tv = (TextView) itemView.findViewById(R.id.item_home_recommend_list_time_tv);


        }
    }
}
